<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
class Users extends Model
{
    //
    protected $table = 'users';

    public function department() {
        return $this->belongsTo('App\Model\Department','department_id');
    }
    public function job(){
        return $this->belongsTo('App\Model\Job','job_id');
    }
    public function place_1()
    {
        return $this->belongsTo('App\Model\Area','province');
    }

    public function place_2()
    {
        return $this->belongsTo('App\Model\Area','city');
    }
    public function place_3()
    {
        return $this->belongsTo('App\Model\Area','district');
    }
    public function place_4()
    {
        return $this->belongsTo('App\Model\Area','street');
    }
    public function place_5()
    {
        return $this->belongsTo('App\Model\Area','community');
    }
    public function cominfo(){
        return $this->belongsTo('App\Model\Company','companyId','id');
    }
    public function resident(){
        return $this->hasOne('App\Model\Resident','user_id','id');
    }
    // 社区管理员的角色
    public function roles(){
        return $this->hasMany('App\Model\AdminUserRoleRelation','user_id','id');
    }
    /**
     * 判断用户是否有权限
     * @param $community
     * @return int|string
     */
    public static function iscommunity($community){
        $com_arr = ['community_admin'=>'community_admin','community_user'=>'community_user'];
        return $com_arr[$community]??0;
    }

    public function menus(){
        return $this->hasMany('App\Model\AdminUserMenuRelation','user_id','id');
    }
    public function menus2(){
        return $this->hasMany('App\Model\AdminUserMenuMRelation','user_id','id');
    }
}
